package com.xhsj.user.hr.process.hrInterviewRegistration.web;

import com.xhsj.user.hr.aspect.OperationPointCut;
import com.xhsj.user.hr.process.dto.hrInterviewRegistration.SaveInterviewRegistrationDto;
import com.xhsj.user.hr.process.dto.hrInterviewRegistration.ShowInterviewRegistrationDto;
import com.xhsj.user.hr.process.hrInterviewRegistration.query.ShowInterviewRegistrationQuery;
import com.xhsj.user.utils.Message;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.*;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;


import com.xhsj.user.hr.process.hrInterviewRegistration.service.TbHrInterviewRegistrationService;
import com.xhsj.user.hr.process.hrInterviewRegistration.entity.TbHrInterviewRegistration;

import javax.validation.Valid;


/**
 * <p>
 * hr面试记录登记表 前端控制器
 * </p>
 *
 * @author liuqinghua
 * @since Sep 4, 2020 11:00:58 AM
 */
@Slf4j
@Api(tags = "hr面试记录登记表")
@RestController
@RequestMapping("/hrInterviewRegistration/tbHrInterviewRegistration")
public class TbHrInterviewRegistrationController {

	@Autowired
    public TbHrInterviewRegistrationService service;


	/**
	 * 保存/修改
	 * @author liuqinghua
	 * @date Sep 4, 2020 11:00:58 AM
	 */
	@ApiOperation(value = "hr面试记录登记表,保存/修改", notes = "hr面试记录登记表,保存和修改方法")
	@RequestMapping(value = "/save", method = RequestMethod.POST)
    @PreAuthorize("hasAuthority('tb:hr:interview:registration:edit')")
	public Message save(@RequestBody TbHrInterviewRegistration data){
    	try {
    		service.save(data);
			return Message.success("成功");
		} catch (Exception e) {
			log.error("保存失败:{}",e);
        	return Message.error(1,"失败");
		}

	}

	/**
	 * 通过id删除数据
	 * @author liuqinghua
	 * @date Sep 4, 2020 11:00:58 AM
	 */
	@ApiOperation(value = "hr面试记录登记表删除", notes = "通过id删除hr面试记录登记表信息。")
	@RequestMapping(value = "/delete", method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('tb:hr:interview:registration:delete')")
	public Message delete(@RequestParam(value="id") Long id) {
		try {
			service.removeById(id);
        	return Message.success("成功");
		} catch (Exception e) {
			log.error("删除失败:{}",e);
            return Message.error(1,"失败");
		}

	}

	/**
	 * 批量删除
	 * @author liuqinghua
	 * @date Sep 4, 2020 11:00:58 AM
	 */
	@ApiOperation(value = "批量删除", notes = "批量删除。")
	@RequestMapping(value = "/batchDelete", method = RequestMethod.POST)
	@PreAuthorize("hasAuthority('tb:hr:interview:registration:delete')")
	public Message batchDelete(@RequestBody List<Long> list) {
		try {
			service.removeByIds(list);
    		return Message.success("成功");
		} catch (Exception e) {
    		log.error("删除失败:{}",e);
    		return Message.error(1,"失败");
		}
    }

    /**
    * 分页查询数据
    * @author liuqinghua
    * @date Sep 4, 2020 11:00:58 AM
    */
	@ApiOperation(value = "分页查询hr面试记录登记表list", notes = "带参数查询,{\"page\": 1,\"size\": 5,......}。支持模糊查询")
	@RequestMapping(value="/findList",method = RequestMethod.POST)
    @PreAuthorize("hasAuthority('tb:hr:interview:registration:view')")
	public Message findList(@RequestBody Map<String,Object> data) {
        try {
        	IPage<TbHrInterviewRegistration> selectPage = service.selectPage(data);
    		return Message.success("成功",selectPage.getRecords(),selectPage.getTotal(),selectPage.getPages());
        } catch (Exception e) {
			log.error("查询异常:{}",e);
    		return Message.error(1,"失败");
        }
	}

    /**
    * 查询所有数据
    * @author liuqinghua
    * @date Sep 4, 2020 11:00:58 AM
    */
	@ApiOperation(value = "查询hr面试记录登记表所有数据list", notes = "查询hr面试记录登记表所有数据list。")
	@RequestMapping(value="/findAll",method = RequestMethod.POST)
    @PreAuthorize("hasAuthority('tb:hr:interview:registration:view')")
	public Message findAll(){
        return Message.success("成功",service.selectAll());
	}

    /**
    * 通过id获取实体类
    * @author liuqinghua
    * @date Sep 4, 2020 11:00:58 AM
    */
	@ApiOperation(value = "通过id获取hr面试记录登记表实体类", notes = "通过id获取hr面试记录登记表实体类。")
	@RequestMapping(value="/getById",method = RequestMethod.GET)
	public Message getById(@RequestParam(value="id") Long id) {
    	return Message.success("成功",service.getById(id));
	}

    /**
    * 通过id查询详细信息
    * @author liuqinghua
    * @date Sep 4, 2020 11:00:58 AM
    */
	@ApiOperation(value = "通过id获取实体类详细信息", notes = "通过id获取实体类详细信息。")
	@RequestMapping(value="/detail",method = RequestMethod.GET)
	public Message detail(@RequestParam(value="id") Long id) {
    	return Message.success("成功",service.getById(id));
	}

	/**
	 * hr面试记录登记表,保存
	 * @author liuqinghua
	 * @date Sep 4, 2020 11:00:58 AM
	 */
	@OperationPointCut(module = "HR模块",operation = "员工面试登记保存")
	@ApiOperation(value = "hr面试记录登记表,保存", notes = "hr面试记录登记表,保存方法")
	@RequestMapping(value = "/saveInterviewRegistration", method = RequestMethod.POST)
// 	@PreAuthorize("hasAuthority('tb:hr:interview:registration:add')")
	public Message saveInterviewRegistration(@RequestBody SaveInterviewRegistrationDto data){
		try {
			service.saveInterviewRegistration(data);
			return Message.success("成功");
		} catch (Exception e) {
			log.error("保存失败:{}",e);
			return Message.error(1,"失败");
		}
	}

	/**
	 * hr面试记录登记表,修改
	 * @author liuqinghua
	 * @date Sep 4, 2020 11:00:58 AM
	 */
	@OperationPointCut(module = "HR模块",operation = "员工面试登记修改")
	@ApiOperation(value = "hr面试记录登记表,修改", notes = "hr面试记录登记表,修改方法")
	@RequestMapping(value = "/updataInterviewRegistration", method = RequestMethod.POST)
// 	@PreAuthorize("hasAuthority('tb:hr:interview:registration:edit')")
	public Message updataInterviewRegistration(@RequestBody SaveInterviewRegistrationDto data){
		try {
			service.updataInterviewRegistration(data);
			return Message.success("成功");
		} catch (Exception e) {
			log.error("保存失败:{}",e);
			return Message.error(1,"失败");
		}
	}

	/**
	 * hr面试记录登记表展示
	 * @author liuqinghua
	 * @date Sep 4, 2020 11:00:58 AM
	 */
	@ApiOperation(value = "hr面试记录登记表展示", notes = "hr面试记录登记表展示")
	@RequestMapping(value = "/showInterviewRegistration", method = RequestMethod.POST)
	@PreAuthorize("hasAuthority('tb:hr:interview:registration:view')")
	public Message showInterviewRegistration(@RequestBody @Valid ShowInterviewRegistrationDto data, BindingResult bindingResult){
		try {
			if (bindingResult.hasErrors()) {
				log.info(bindingResult.getFieldError().getDefaultMessage());
				return Message.error(1,bindingResult.getFieldError().getDefaultMessage());
			}
            IPage<ShowInterviewRegistrationQuery> showInterviewRegistrationQueryIPage = service.showInterviewRegistration(data);
            return Message.success("成功",showInterviewRegistrationQueryIPage.getRecords(),
                    showInterviewRegistrationQueryIPage.getTotal(),showInterviewRegistrationQueryIPage.getPages());
		} catch (Exception e) {
			log.error("保存失败:{}",e);
			return Message.error(1,"失败");
		}
	}

	/**
     * hr面试记录登记表具体数据
     * @author liuqinghua
     * @date Sep 4, 2020 11:00:58 AM
     */
    @ApiOperation(value = "hr面试记录登记表具体数据", notes = "hr面试记录登记表具体数据")
    @GetMapping(value = "/showInterviewRegistrationDetail")
//    @PreAuthorize("hasAuthority('tb:hr:interview:registration:detail:view')")
    public Message showInterviewRegistrationDetail(@RequestParam(value = "id") Long id){
        try {
            return Message.success("成功",service.showInterviewRegistrationDetail(id));
        } catch (Exception e) {
            log.error("保存失败:{}",e);
            return Message.error(1,"失败");
        }
    }

    /**
     * 删除hr面试记录登记表
     * @author liuqinghua
     * @date Sep 4, 2020 11:00:58 AM
     */
	@OperationPointCut(module = "HR模块",operation = "删除hr面试记录登记表")
    @ApiOperation(value = "删除hr面试记录登记表", notes = "删除hr面试记录登记表")
    @GetMapping(value = "/deleteInterviewRegistration")
//	@PreAuthorize("hasAuthority('tb:hr:interview:registration:delete')")
    public Message deleteInterviewRegistration(@RequestParam(value = "dataId") Long dataId){
        try {
			service.deleteInterviewRegistration(dataId);
            return Message.success("成功");
        } catch (Exception e) {
            log.error("保存失败:{}",e);
            return Message.error(1,"失败");
        }
    }

}

